queue = {
    _ensureProcessing: ()=>{
      //如果当前已经在执行的任务小于并发任务数的话
      while (this._activeTasks < this._parallelism) {
          //取得最先加入的任务，或者说队头的任务
          const entry = this._queued.dequeue()
          if(!entry) break;
          this._activeTasks++; //让当前正在执行的并发任务数增加1
          entry.state = PROCESSING_STATE; //把条目的状态设置为执行中
          this._startProcessing(entry);//开始处理此条目
      }
      this._willEnsureProcessing = false;
    },
    _name: "创建模块", //队列的名称
    _parallelism: 3, //并发的个数
    _processor: function processor(item, callback) { //每个条目的处理器
      setTimeout(() => {
          console.log('处理', item);
          callback(null, item);
      }, 3000);
    },
    _getKey: function getKey(item) { //每个条目的唯一标识获取函数
      return item.key;
    },
    _entries: { //用来判断此条目是否已经添加过
    },
    _queued: { //内部真正用来存放条目
      _list: [
      ],
    },
    _activeTasks: 0, //当前正在执行的任务数
    _willEnsureProcessing: false, //是否要马上开始处理任务
  }

  key = 'item1'
  oldEntry = undefined
  newEntry =  {
    item: {
      key: "item1",
    },
    state: 0,
    callback: (err, result) => {
      console.log(err, result);
      console.log('完成item1过去', Date.now() - startTime);
    },
  }
  queue = {
    _ensureProcessing: ()=>{
      //如果当前已经在执行的任务小于并发任务数的话
      while (this._activeTasks < this._parallelism) {
          //取得最先加入的任务，或者说队头的任务
          const entry = this._queued.dequeue()
          if(!entry) break;
          this._activeTasks++; //让当前正在执行的并发任务数增加1
          entry.state = PROCESSING_STATE; //把条目的状态设置为执行中
          this._startProcessing(entry);//开始处理此条目
      }
      this._willEnsureProcessing = false;
    },
    _name: "创建模块",
    _parallelism: 3,
    _processor: function processor(item, callback) {
      setTimeout(() => {
          console.log('处理', item);
          callback(null, item);
      }, 3000);
    },
    _getKey: function getKey(item) {
      return item.key;
    },
    _entries: {
        "item1":{
            item: {
              key: "item1",
            },
            state: 0,
            callback: (err, result) => {
              console.log(err, result);
              console.log('完成item1过去', Date.now() - startTime);
            },
        },
    },
    _queued: {
      _list: [
        {
          item: {
            key: "item1",
          },
          state: 0,
          callback: (err, result) => {
            console.log(err, result);
            console.log('完成item1过去', Date.now() - startTime);
          },
        },
      ],
    },
    _activeTasks: 0,
    _willEnsureProcessing: true,
  }

  queue = {
    _ensureProcessings: ()=>{
      //如果当前已经在执行的任务小于并发任务数的话
      while (this._activeTasks < this._parallelism) {
          //取得最先加入的任务，或者说队头的任务
          const entry = this._queued.dequeue()
          if(!entry) break;
          this._activeTasks++; //让当前正在执行的并发任务数增加1
          entry.state = PROCESSING_STATE; //把条目的状态设置为执行中
          this._startProcessing(entry);//开始处理此条目
      }
      this._willEnsureProcessing = false;
    },
    _name: "创建模块",
    _parallelism: 1,
    _processor: function processor(item, callback) {
      setTimeout(() => {
          console.log('处理', item);
          callback(null, item);
      }, 3000);
    },
    _getKey: function getKey(item) {
      return item.key;
    },
    _entries: {
        "item1":{
            item: {
              key: "item1",
            },
            state: 0,
            callback: (err, result) => {
              console.log(err, result);
              console.log('完成item1过去', Date.now() - startTime);
            },
          },
        "item2":{
            item: {
              key: "item2",
            },
            state: 0,
            callback: (err, result) => {
              console.log(err, result);
              console.log('完成item2过去', Date.now() - startTime);
            },
          },
        "item3":{
            item: {
              key: "item3",
            },
            state: 0,
            callback: (err, result) => {
              console.log(err, result);
              console.log('完成item3过去', Date.now() - startTime);
            },
          },


    },
    _queued: {
      _list: [
        {
          item: {
            key: "item1",
          },
          state: 0,
          callback: (err, result) => {
            console.log(err, result);
            console.log('完成item1过去', Date.now() - startTime);
          },
        },
        {
          item: {
            key: "item2",
          },
          state: 0,
          callback: (err, result) => {
            console.log(err, result);
            console.log('完成item2过去', Date.now() - startTime);
          },
        },
        {
          item: {
            key: "item3",
          },
          state: 0,
          callback: (err, result) => {
            console.log(err, result);
            console.log('完成item3过去', Date.now() - startTime);
          },
        },
      ],
    },
    _activeTasks: 0,
    _willEnsureProcessing: true,
  }

  queue= {
    _ensureProcessing: ()=>{
      //如果当前已经在执行的任务小于并发任务数的话
      while (this._activeTasks < this._parallelism) {
          //取得最先加入的任务，或者说队头的任务
          const entry = this._queued.dequeue()
          if(!entry) break;
          this._activeTasks++; //让当前正在执行的并发任务数增加1
          entry.state = PROCESSING_STATE; //把条目的状态设置为执行中
          this._startProcessing(entry);//开始处理此条目
      }
      this._willEnsureProcessing = false;
    },
    _name: "创建模块",
    _parallelism: 3,
    _processor: function processor(item, callback) {
      setTimeout(() => {
          console.log('处理', item);
          callback(null, item);
      }, 3000);
    },
    _getKey: function getKey(item) {
      return item.key;
    },
    _entries: {
        "item1":{
            item: {
              key: "item1",
            },
            state: 0,
            callback: (err, result) => {
              console.log(err, result);
              console.log('完成item1过去', Date.now() - startTime);
            },
            callbacks: [
                (err, result) => {
                  console.log(err, result);
                  console.log('完成item4过去', Date.now() - startTime);
                },
                (err, result) => {
                  console.log(err, result);
                  console.log('完成item5过去', Date.now() - startTime);
                },
              ],
          },
        "item2":{
            item: {
              key: "item2",
            },
            state: 0,
            callback: (err, result) => {
              console.log(err, result);
              console.log('完成item2过去', Date.now() - startTime);
            },
          },
        "item3":{
            item: {
              key: "item3",
            },
            state: 0,
            callback: (err, result) => {
              console.log(err, result);
              console.log('完成item3过去', Date.now() - startTime);
            },
          },
    },
    _queued: {
      _list: [
        {
          item: {
            key: "item1",
          },
          state: 0,
          callback: (err, result) => {
            console.log(err, result);
            console.log('完成item1过去', Date.now() - startTime);
          },
          callbacks: [
            (err, result) => {
              console.log(err, result);
              console.log('完成item4过去', Date.now() - startTime);
            },
            (err, result) => {
              console.log(err, result);
              console.log('完成item5过去', Date.now() - startTime);
            },
          ],
        },
        {
          item: {
            key: "item2",
          },
          state: 0,
          callback: (err, result) => {
            console.log(err, result);
            console.log('完成item2过去', Date.now() - startTime);
          },
        },
        {
          item: {
            key: "item3",
          },
          state: 0,
          callback: (err, result) => {
            console.log(err, result);
            console.log('完成item3过去', Date.now() - startTime);
          },
        },
      ],
    },
    _activeTasks: 0,
    _willEnsureProcessing: true,
  }


  entry = {
    item: {
      key: "item1",
    },
    state: 0,
    callback: (err, result) => {
      console.log(err, result);
      console.log('完成item1过去', Date.now() - startTime);
    },
    callbacks: [
      (err, result) => {
        console.log(err, result);
        console.log('完成item4过去', Date.now() - startTime);
      },
      (err, result) => {
        console.log(err, result);
        console.log('完成item5过去', Date.now() - startTime);
      },
    ],
  }

// 执行this.processor函数，和执行_handleResult
entry = {
    item: {
      key: "item1",
    },
    state: 2,
    callback: (err, result) => {
      console.log(err, result);
      console.log('完成item1过去', Date.now() - startTime);
    },
    callbacks: [
      (err, result) => {
        console.log(err, result);
        console.log('完成item4过去', Date.now() - startTime);
      },
      (err, result) => {
        console.log(err, result);
        console.log('完成item5过去', Date.now() - startTime);
      },
    ],
    result: {
      key: "item1",
    },
    error: null,
  }